<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Teacher;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;
use function foo\func;

class TeacherController extends AdminController
{

    public function index(Content $content)
    {
        return $content->title('教员')
            ->description('列表')
            ->body($this->grid());
    }
    public function create(Content $content)
    {
        return $content->title('教员')
            ->description('新增')
            ->body($this->form());
    }
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Teacher(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('user_name');
            $grid->column('height')->display(function ($value){
                return $value.'cm';
            });
            $grid->column('weight')->display(function ($value){
                return $value.'kg';
            });;
            $grid->column('school');
            $grid->column('honor');
            $grid->column('header_img')->image('',100,100);
            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Teacher(), function (Show $show) {
            $show->field('id');
            $show->field('user_name');
            $show->field('school');
            $show->field('honor');
            $show->field('height');
            $show->field('weight');
            $show->field('header_img');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Teacher(), function (Form $form) {
            $form->display('id');
            $form->text('user_name');
            $form->text('school');
            $form->text('honor');
            $form->text('height')->help('默认cm');
            $form->text('weight')->help('默认kg');;
            $form->file('header_img')->autoUpload()->uniqueName();;
        });
    }
    public function teacherDate(){
        $OwnerData = \App\Models\Teacher::get(['id','user_name as text'])->toArray();
        return $OwnerData;
    }
}
